package edu.umn.se.trap.logicChecker;

import java.util.Observable;
import java.util.Observer;

import edu.umn.se.trap.Form;
import edu.umn.se.trap.TravelDetails;
import edu.umn.se.trap.exceptions.TravelDetailsException;

public class CheckSyntaxTravelDetails implements Observer {

    @Override
    /**
     * Update for checking syntax for TravelDetails
     */
    public void update(Observable o, Object arg) {
       
       Form form = (Form) arg;    
       LogicChecker l1 = (LogicChecker)o;
       TravelDetails travelD = form.getTravelDetails();
       

       if (!travelD.getEmergencyContact().equals(""))

       {
           if (travelD.getEmergencyContactTelNum().equals(""))
           {
               l1.setException(new TravelDetailsException("Error: No emergency contact number provided."));
           }
       }
       else
       {
           l1.setException(new TravelDetailsException("Error: No emergency contact provided."));
       }
       
       if (travelD.getCSE_sponsored() || travelD.getDTC_sponsored())
       {
           if (travelD.getJustSponsored().equals(""))
           {
               l1.setException(new TravelDetailsException("Error: No justification for sponsored funds."));
           }
       }
       if (travelD.getNonsponsored() == true)
       {
           if (travelD.getJustNonsponsored().equals(""))
           {
               l1.setException(new TravelDetailsException("Error: No Justification for Non-sponsored funds."));
           }
       }
       if (travelD.getJustConfTitle().equals(""))
       {
           l1.setException(new TravelDetailsException("Error: No conference title provided."));
       }
       if (travelD.getJustPresented() == true)
       {
           if (travelD.getJustPresentationTitle().equals("") || 
                   travelD.getJustPresentationAbstract().equals("") ||
                   travelD.getJustPresentationAcknowledgement().equals(""))
           {
               l1.setException(new TravelDetailsException("Error: Presentation justification no provided."));
           }   
       }
    }
}